package com.tang.algorithm.swordFingerOffer;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/7/26 19:45
 * <p>
 * 两个链表的第一个公共节点
 */
public class sword52 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) {
            return null;
        }
        ListNode listNode1 = headA;
        ListNode listNode2 = headB;
        while (headA != headB) {
            if (headA != null) {
                headA = headA.next;
            } else {
                headA = listNode2;
            }

            if (headB != null) {
                headB = headB.next;
            } else {
                headB = listNode1;
            }
        }
        return headA;
    }
}
